import Vue from 'vue'
import VueRouter from 'vue-router'
const Login = () => import(/* webpackChunkName:"login_home_welcome" */ '@/components/Login/login.vue')
const Home = () => import(/* webpackChunkName:"login_home_welcome" */ '@/components/Home/index.vue')
const Welcome = () => import(/* webpackChunkName:"login_home_welcome" */ '@/components/Home/list.vue')
const Users = () => import(/* webpackChunkName:"user" */ '@/components/User/users.vue')
const Rights = () => import(/* webpackChunkName:"power" */ '@/components/Authority/rights.vue')
const Roles = () => import(/* webpackChunkName:"power" */ '@/components/Authority/roles.vue')
const Cate = () => import(/* webpackChunkName:"goods" */ '@/components/goods/categories.vue')
const Params = () => import(/* webpackChunkName:"goods" */ '@/components/goods/params.vue')
const GoodList = () => import(/* webpackChunkName:"goods" */ '@/components/goods/goods.vue')
const GoodAdd = () => import(/* webpackChunkName:"goods" */ '@/components/goods/getAdd.vue')
const Order = () => import(/* webpackChunkName:"order" */ '@/components/Orders/orders.vue')
const Report = () => import(/* webpackChunkName:"report" */ '@/components/Reports/reports.vue')

Vue.use(VueRouter)

const routes = [
  { path: '/', redirect: '/login' },
  { path: '/login', component: Login },
  {
    path: '/home', component: Home, redirect: '/welcome', children: [
      { path: "/welcome", component: Welcome },
      { path: "/users", component: Users },
      { path: "/rights", component: Rights },
      { path: "/roles", component: Roles },
      { path: "/categories", component: Cate },
      { path: "/params", component: Params },
      { path: "/goods", component: GoodList },
      { path: "/add", component: GoodAdd },
      { path: "/orders", component: Order },
      { path: "/reports", component: Report },

    ],

    // 单个路由守卫
    beforeEnter: (to, from, next) => {
      // 
      if (!sessionStorage.getItem('loginmsg')) {
        alert('请先登录')
        next('/login')
      } else {
        next()
      }
    }
  }
]

const router = new VueRouter({
  routes
})

export default router
